package training;

import java.util.PriorityQueue;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_6_19_Training {
    //划分数组使最大差为 K
    public int partitionArray(int[] nums, int k) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((a, b)->b-a);
        for (int n:nums)queue.add(n);
        int max = queue.poll();
        int res=0;
        while (queue.size()!=0){
            int t = queue.poll();
            if (max-t>k){
                res++;
                max=t;
            }
        }
        return res+1;
    }
}
